<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
    <link rel="stylesheet" href="/css/formSelects-v4.css" />
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<form class="layui-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">用户名</label>
        <div class="layui-input-block">
            <input type="text"  lay-verify="required" lay-reqtext="用户名不能为空" name="name" placeholder="请输入用户名" value="zhangsan" class="layui-input">
            <tip>填写自己想要新增的名称。</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">账号</label>
        <div class="layui-input-block">
            <input type="text" lay-verify="required" placeholder="请输入密码" class="layui-input" name="account" value="root" >
            <tip>填写新增的账号。</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">密码</label>
        <div class="layui-input-block">
            <input type="password" lay-verify="required" placeholder="请输入密码" class="layui-input" name="password" value="1234" >
            <tip>请填写密码。</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">状态</label>
        <div class="layui-input-inline" style="width: 200px;">
            <select name="status" class="city-selector" data-value="" lay-filter="city-1">
                <option value="">请选择状态</option>
                <option value="0">启用</option>
                <option value="1">禁用</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">添加角色</label>
        <div class="layui-input-inline" style="width: 56%;">
            <select name="tags" id="tags" lay-verify="required" xm-select="tags" xm-select-skin="normal">
                <option value="">请选择</option>
                <option th:each="role:${roleList}" th:text="${role.name}" th:value="${role.id}" ></option>
            </select>
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</form>
<script src="/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>

    //全局定义一次, 加载formSelects
    layui.config({
        base: '/lib/layui-v2.5.5/' //此处路径请自行处理, 可以使用绝对路径
    }).extend({
        formSelects: 'formSelects-v4'
    });
    //加载模块

    layui.use(['form','formSelects'], function () {
        var form = layui.form,
            layer = layui.layer,
            formSelects = layui.formSelects,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var roleIdArray = new Array();
            roleIdArray = formSelects.value('tags','val')
            layer.msg("数据提交中。。。。");
            $.ajax({
                url:"/addUser?rolelist="+roleIdArray,
                type:"post",
                dataType:"json",
                contentType:"application/json;",
                data:JSON.stringify(data.field),
                success:function () {
                        layer.msg("数据提交成功！")
                        window.location.reload()
                }
            })
            return false;
        });

    });
</script>
</body>
</html>